package Practice18;

public class BaoZiPu extends Thread {
    private BaoZi baozi;

    BaoZiPu(String name, BaoZi baozi) {
        super(name);
        this.baozi = baozi;
    }

    @Override
    public void run() {
        int count = 0;
        while (true) {
            synchronized (baozi) {
                if (baozi.flag) {
                    try {
                        baozi.wait();
                    } catch (InterruptedException e) {
                        e.fillInStackTrace();
                    }
                }
                System.out.println("包子开始做包子");
                if (count % 2 == 0) {
                    baozi.pier = "冰皮";
                    baozi.xianer = "伍仁";
                } else {
                    baozi.pier = "薄皮";
                    baozi.xianer = "牛肉大葱";
                }
                count++;
                baozi.flag = true;
                System.out.println("包子早好了：" + baozi.pier + baozi.xianer);
                System.out.println("吃货来吃吧");
                // 唤醒等待线程（吃货）
                baozi.notify();
            }

        }
    }
}
